﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace Fusion
{

    /// <summary> Static Interface drawing methods </summary>
    public class UI
    {
        public static Texture2D pixel = Engine.SysTextures.Get( "pixel" );        

        // Draws a block of color
        public static void DrawBlock( float left, float top, float right, float bottom, Color Color )
        {
            Rectangle dest = new Rectangle( ( int )left, ( int )top, ( int )( right - left ), ( int )( bottom - top ) );
            Engine.spriteBatch.Draw( pixel, dest, Color );
        }
        public static void DrawBlock( Vector2 Position, Vector2 Size, float angle, Color Color )
        {
            Rectangle dest = new Rectangle( ( int )( Position.X ), ( int )( Position.Y ), ( int )Size.X, ( int )Size.Y );
            Engine.spriteBatch.Draw( pixel, dest, new Rectangle( 0, 0, 1, 1 ), Color, angle, Vector2.Zero, SpriteEffects.None, 0.5f );
        }
        public static void DrawBlock( Rectangle dest, float angle, Color Color )
        {
            Engine.spriteBatch.Draw( pixel, dest, new Rectangle(0,0,1,1), Color, angle, Vector2.Zero, SpriteEffects.None, 0.5f );
        }

        // Draws an outline box
        public static void DrawBox( float left, float top, float right, float bottom, Color Color )
        {
            Engine.spriteBatch.Draw( pixel, new Rectangle( (int)(left), (int)(top), 1, (int)(bottom - top) ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( (int)(right), (int)(top), 1, (int)(bottom - top) ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( (int)(left), (int)(top), (int)(right - left), 1 ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( (int)(left), (int)(bottom), (int)(right - left) + 1, 1 ), Color );
        }
        public static void DrawBox( Vector2 Position, Vector2 Size, Color Color )
        {
            int left = ( int )( Position.X  );
            int right = ( int )( Position.X + Size.X );
            int top = ( int )( Position.Y  );
            int bottom = ( int )( Position.Y + Size.Y );

            Engine.spriteBatch.Draw( pixel, new Rectangle( left, top, 1, bottom - top ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( right, top, 1, bottom - top ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( left, top, right - left, 1 ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( left, bottom, right - left + 1, 1 ), Color );
        }
        public static void DrawBox( Rectangle dest, Color Color )
        {
            int left = dest.X;
            int right = dest.X + dest.Width;
            int top = dest.Y;
            int bottom = dest.Y + dest.Height;

            Engine.spriteBatch.Draw( pixel, new Rectangle( left, top, 1, bottom - top ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( right, top, 1, bottom - top ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( left, top, right - left, 1 ), Color );
            Engine.spriteBatch.Draw( pixel, new Rectangle( left, bottom, right - left + 1, 1 ), Color );
        }

        // Draws a grid.
        public static void DrawGrid( Vector2 Position, Vector2 Size, Vector2 CellSize, Color Color )
        {
            int left = ( int )( Position.X );
            int right = ( int )( Position.X + Size.X );
            int top = ( int )( Position.Y );
            int bottom = ( int )( Position.Y + Size.Y );
            int w = (int)CellSize.X;
            int h = (int)CellSize.Y;

            // Horizontal Lines
            for( int i = 0; i <= (bottom-top) / h; i++ )
                Engine.spriteBatch.Draw( pixel, new Rectangle( left, top + (i * h), right - left, 1 ), Color );

            // Vertical Lines
            for( int i = 0; i <= (right-left) / h; i++ )
                Engine.spriteBatch.Draw( pixel, new Rectangle( left + (i * h), top, 1, bottom-top ), Color );
        }
        public static void DrawGrid( Rectangle dest, Vector2 CellSize, Color Color )
        {
            int left = dest.X;
            int right = dest.X + dest.Width;
            int top = dest.Y;
            int bottom = dest.Y + dest.Height;
            int w = ( int )CellSize.X;
            int h = ( int )CellSize.Y;

            // Horizontal Lines
            for( int i = 0; i <= ( bottom - top ) / h; i++ )
                Engine.spriteBatch.Draw( pixel, new Rectangle( left, top + ( i * h ), right - left+1, 1 ), Color );

            // Vertical Lines
            for( int i = 0; i <= ( right - left ) / h; i++ )
                Engine.spriteBatch.Draw( pixel, new Rectangle( left + ( i * h ), top, 1, bottom - top+1 ), Color );
        }
    }
}
